package cn.itcast.listener;

import cn.itcast.domain.system.User;
import cn.itcast.utils.MailUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;


/**
 * 消息的监听器
 */
public class DPEmailListener implements MessageListener {

    private ObjectMapper objectMapper = new ObjectMapper();

    @Override
    public void onMessage(Message message) {
        byte[] body = message.getBody();
        try {
            User user = objectMapper.readValue(body, User.class);
            /*
            sendMsg()方法的三个参数：（1）收件人 （2）发送的主题 （3）发送的内容
            */
            MailUtil.sendMsg(user.getEmail(),"温馨提示","您的购销合同交期仅剩三天了哦");
            System.out.println("邮件发送成功！");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
